<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8" %>
<%@page import="java.util.Arrays" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="header.jsp">
	<jsp:param name="title" value="添加菜单"/>
</jsp:include>
<form action="${requestScope.config.site_root}/admin?c=menu&a=add" method="post" name="myform" onsubmit="return checkForm()">
	<table cellpadding="2" cellspacing="1" class="table_form">
		<caption><c:choose><c:when test="${null ne requestScope.menu}">编辑菜单</c:when><c:otherwise>添加菜单</c:otherwise></c:choose></caption>
		<tr>
			<th width="30%"><strong>父菜单</strong></th>
			<td><span id="container"></span><span><a href="javascript:getChildMenu('container',0);">重选</a></span></td>
		</tr>
		<tr>
			<th width="30%"><strong>菜单名</strong></th>	
			<td><input type="text" name="menuname" value="${requestScope.menu.menu_name}"></td>
		</tr>
		<tr>
			<th width="30%"><strong>Controller Name</strong></th>	
			<td><input type="text" name="controller" value="${requestScope.menu.c}"></td>
		</tr>  
		<tr>
			<th width="30%"><strong>Action Name</strong></th>	
			<td><input type="text" name="action" value="${requestScope.menu.a}"></td>
		</tr>
		<tr>
			<th width="30%"><strong>是否可见</strong></th>
			<td><input type="radio" name="notshow" value="0"<c:if test="${empty($requestScope.menu) || $requestScope.menu.notshow eq 0}"> checked</c:if>>是 <input type="radio" name="notshow" value="1"<c:if test="${$requestScope.menu.notshow eq 1}"> checked</c:if>>否</td>
		</tr>
		<tr>
			<th><strong>权限设置</strong></th>
			<td id="groups">
				<c:if test="${null ne requestScope.menu}">
				<c:if test="${null eq requestScope.parent || null eq requestScope.parentGids}">
				<p style="height:20px;width:90%;border-bottom:dashed 1px blue;padding-bottom:5px;margin-bottom:5px;">
					<input type="checkbox" name="open" value="1"<c:if test="${null eq requestScope.groupIds}"> checked</c:if> style="vertical-align:middle;"/><span style="padding-left:1px;">不限</span><span style="color:red;">[勾选此处后虚线下方的选项将被忽略]</span>
				</p>
				</c:if>
				<span style="color:green;padding-right:4px;">超级管理员${requestScope.groupIds[1]}</span>
				<c:forEach items="${requestScope.groups}" var="group" varStatus="index">
				<c:if test="${group.key ne 1}">
				<c:set var="groupid" value="${group.key}" scope="request"/>
				<input type="checkbox" name="groups" value="${group.key}"<%
				if(null != request.getAttribute("groupIds") && 0 <=  Arrays.binarySearch((String[])request.getAttribute("groupIds"), String.valueOf(request.getAttribute("groupid")))) {
					out.print(" checked");
				}
				%> style="vertical-align:middle;"><span style="padding-left:4px;color:blue;">${group.value}</span>
				</c:if>
				</c:forEach>
				</c:if>
			</td>
		</tr>
		<c:if test="${requestScope.menu.isdir eq 1}">
		<tr>
			<th><strong>应用到子菜单</strong></th>
			<td><input type="checkbox" name="usetochild" value="1" style="vertical-align:middle;"/><span style="color:red;">[是否对子菜单应用相同权限]</span></td>
		</tr>
		</c:if>
		<tr>
			<th></th>
			<td>
				<input type="submit" name="doadd" class="button_style" value=" 确定 "> 
				<input type="reset" name="reset" class="button_style" value=" 清除 ">
			</td>
		</tr>
	</table>
	<input type="hidden" name="groups" value="1"/>
	<c:if test="${null ne requestScope.menu}"><input type="hidden" name="id" value="${id}"/></c:if>
</form>
<p>&nbsp;<font color="#FF0000">注意：若此菜单不是文件夹，则程序将试图去访问：/admin?c=[controller]&a=[actionname] 的链接</font></p>
<jsp:include page="footer.jsp"/>
<script language="javascript">
function getChildMenu(c, mix) {
	var pid = mix == 0 ? 0 : mix.value;
	var url = '${requestScope.config.site_root}/admin?c=menu&a=getchild&pid='+pid;
	$.get(url,function(data){
		pid == 0 ? $('#'+c).html(data) : $('#'+c).append(data);
		if(mix != 0) mix.disabled = true;
	});
}

function checkForm() {
	if(myform.menuname.value == '') {
		alert('菜单名不能为空！');
		return false;
	}
	var parents = document.getElementsByName('parents');
	for(var i = 0; i < parents.length; i++) {
		parents[i].disabled = false;
	}
	
	return true;
}

<c:if test="${empty(requestScope.menu)}">getChildMenu('container',0);</c:if>
</script>